package cn.nawang.ebeim.client.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import cn.nawang.ebeim.client.version.VersionTree;

public class JavaSerializer implements VersionTreeSerializer {

  @Override
  public void writeObject(String path, VersionTree vt) throws FileNotFoundException, IOException {
    ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(path));
    os.writeObject(vt);
    os.close();
  }

  @Override
  public VersionTree readObject(String path)
      throws FileNotFoundException, IOException, ClassNotFoundException {
    ObjectInputStream is = new ObjectInputStream(new FileInputStream(path));
    VersionTree vt = (VersionTree) is.readObject();
    is.close();
    return vt;
  }

}
